package com.sinoglobal.ningxia.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.sinoglobal.ningxia.R;
import com.sinoglobal.ningxia.beans.PhotoInfoVo;
import com.sinoglobal.ningxia.http.ConnectionUtil;

import net.tsz.afinal.FinalBitmap;

import java.util.ArrayList;

/**
 * 
 * @author hxp
 * @createdate 2014-6-19 下午5:35:27
 * @Description:商家详情图片适配器
 */
public class PhotoWallAdapter extends BaseAdapter {
	private ArrayList<PhotoInfoVo> infoes;// 照片信息集合
	private LayoutInflater layoutInflater;// 布局解析器
	private FinalBitmap afinal;

	public PhotoWallAdapter(Context context, ArrayList<PhotoInfoVo> infoes) {
		this.infoes = infoes;
		layoutInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
		afinal = FinalBitmap.create(context);
		afinal.configLoadfailImage(R.drawable.default43);
		afinal.configLoadingImage(R.drawable.default43);
	}

	public void setData(ArrayList<PhotoInfoVo> infoes) {
		this.infoes = infoes;
		this.notifyDataSetChanged();
	}

	@Override
	public int getCount() {
		return infoes.size();
	}

	@Override
	public Object getItem(int position) {
		return infoes.get(position);
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		Com com;
		final PhotoInfoVo photoInfo = infoes.get(position);
		if (null == convertView) {
			com = new Com();
			convertView = layoutInflater.inflate(R.layout.photo_wall_item, null);
			com.img = (ImageView) convertView.findViewById(R.id.photo_item_img);
			com.info = (TextView) convertView.findViewById(R.id.photo_item_disc);
			convertView.setTag(com);
		} else {
			com = (Com) convertView.getTag();
		}
		com.info.setText(photoInfo.getContent());
		afinal.display(com.img, ConnectionUtil.localUrl + photoInfo.getImg());
		OnClickListener listener = new OnClickListener() {

			@Override
			public void onClick(View v) {
				// Intent intent = new Intent(context,PhotoBigActivity.class);
				// intent.putExtra(PhotoBigActivity.PHOTOBIG, photoInfo);
				// context.startActivity(intent);
			}
		};
		com.info.setOnClickListener(listener);
		com.img.setOnClickListener(listener);

		return convertView;
	}

	/**
	 * item 重用辅助类
	 * 
	 * @author hxp
	 * @createdate 2014-6-23 下午4:59:37
	 * @Description:
	 */
	class Com {
		TextView info;
		ImageView img;
	}
}
